#! /usr/bin/perl
use strict;
use Getopt::Long;
my $rename = '';
my $help;
my $usage = <<EOT;

bong - interface generator for HelFORTH
Copyright (c) 2006 Helmar Wodtke

usage:
  $0 [options] library.so

where options include:

  -rename '..script..'      define rename script
  -help                     display help screen

EOT
GetOptions (
  "help" => \$help,
  "h" => \$help,
  "rename=s" => \$rename,
) or die $usage;

if ($help || $#ARGV != 0) {
  print $usage;
  exit 0;
}
my %syms;
open OBJDMP, "objdump -T $ARGV[0] |" or die;
while (<OBJDMP>) {
	my @line = split/\s+/;
	$syms{$line[6]} = 1;
}
close OBJDMP;
while (<STDIN>) {
	if (/ifgen:\s+\S+\s+(\S+)/) {
		our $name = $1;
		eval $rename;
		if (not defined $syms{$name}) {
			warn "symbol $1 not existing\n";
			next;
		}
	}
	print $_;
}
